#!/usr/bin/node

const http = require('http'),
      log = require('util').debuglog('dev'),
      fs = require('fs');

http.createServer((req,res)=>{
  log(`${req.methon} ${req.url} HTTP/${req.httpVersion}`);
  log(req.headers);
  log(process.pid);
  log();
  let filename = __dirname + req.url;

  if(fs.existsSync(filename)){
    fs.createReadStream(filename).pipe(res);
  }else{
    res.statusCode = 404;
    res.end(req.url+'not exist!');
  }

}).listen('8080');
